﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace Lamex.Common
{
   public class SystemConfig
   {
       private static SystemConfig _CurrentConfig;
       private bool _DoubleClickIntoEditMode = false;
       public static SystemConfig CurrentConfig
       {
           get
           {
               return _CurrentConfig;
           }
           set
           {
               _CurrentConfig = value;
           }
       }
       /// <summary>
       /// 双击表格进入编辑模式
       /// </summary>
       public bool DoubleClickIntoEditMode
       {
           get { return _DoubleClickIntoEditMode; }
           set { _DoubleClickIntoEditMode = value; }
       }

       public static void WriteSettings(SystemConfig config)
       {
           XmlSerializer xs = new XmlSerializer(typeof(SystemConfig));
           Stream stream = new FileStream(GetConfigPath(), FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
           xs.Serialize(stream, config);
           stream.Close();
       }

       public static void ReadSettings()
       {
           string path = GetConfigPath();
           if (!File.Exists(path))
           {
               SystemConfig.CurrentConfig = new SystemConfig();
               WriteSettings(SystemConfig.CurrentConfig);
           }
           else
           {
               XmlSerializer xs = new XmlSerializer(typeof(SystemConfig));
               Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
               CurrentConfig = (SystemConfig)xs.Deserialize(stream);
               stream.Close();
           }
       }
       private static string GetConfigPath()
       {
           return Application.StartupPath + @"\config\SystemSettings.xml";
       }

       /// <summary>
       /// 皮肤名称
       /// </summary>
       string _SkinName = "";
       public string SkinName
       {
           get { return _SkinName; }
           set { _SkinName = value; }
       }
   }
}
